<?php
/**
 * 推荐商品
 * User: yuanxuncheng
 * Date: 2016-12-21
 * Time: 22:39
 */

namespace app\api\model\dao;

use think\Model;
use think\Db;

class GoodsRecommend extends Model
{
    //set talbename
    protected $table = 'goods_recommend';
    //set primary key
    protected $pk = 'goods_id';

    /**
     * @desc 添加推荐商品
     * @param $goods_id
     * @param $recommend_goods_id
     * @return false|int
     */
    public function addGoodsRecommend($goods_id, $recommend_goods_id)
    {
        $param['goods_id'] = $goods_id;
        $param['recommend_goods_id'] = $recommend_goods_id;
        $this->data($param);
        return $this->save();
    }

    /**
     * @desc 获取推荐商品
     * @param $goods_id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getGoodsRecommend($goods_id)
    {
        $conds = array(
            'goods_id' => $goods_id,
        );
        $field = '*';
        return Db::table($this->table)->where($conds)->field($field)->select();
    }
}
